package com.shure.surdes.modules.survey.controller;

import com.shure.surdes.common.result.R;
import com.shure.surdes.common.result.Result;
import com.shure.surdes.modules.survey.domain.Options;
import com.shure.surdes.modules.survey.service.IOptionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问卷选项Controller
 *
 * @author Shure
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/survey/options")
public class OptionsController {

    @Autowired
    private IOptionsService optionsService;

    /**
     * 查询问卷选项列表
     */
    @GetMapping("/list")
    public R list(Options options) {
        List<Options> list = optionsService.selectOptionsList(options);
        return Result.ok(list);
    }

    /**
     * 导出问卷选项列表
     */
    @GetMapping("/export")
    public R export(Options options) {
        List<Options> list = optionsService.selectOptionsList(options);
        return Result.ok(list);
    }

    /**
     * 获取问卷选项详细信息
     */
    @GetMapping(value = "/{optionId}")
    public R getInfo(@PathVariable("optionId") Long optionId) {
        return Result.ok(optionsService.selectOptionsByOptionId(optionId));
    }

    /**
     * 新增问卷选项
     */
    @PostMapping
    public R add(@RequestBody Options options) {
        return Result.ok(optionsService.insertOptions(options));
    }

    /**
     * 修改问卷选项
     */
    @PutMapping
    public R edit(@RequestBody Options options) {
        return Result.ok(optionsService.updateOptions(options));
    }

    /**
     * 删除问卷选项
     */
    @DeleteMapping("/{optionIds}")
    public R remove(@PathVariable Long[] optionIds) {
        return Result.ok(optionsService.deleteOptionsByOptionIds(optionIds));
    }
}
